package com.yocard.yxyd.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.gyf.barlibrary.ImmersionBar;
import com.yocard.yxyd.R;
import com.yocard.yxyd.base.Constants;
import com.yocard.yxyd.http.model.response.CommonBean;
import com.yocard.yxyd.ui.activity.base.SimpleActivity;
import com.yocard.yxyd.utils.util.ActivityUtils;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created on 2019/4/24.
 * 充值结果 19/05/04
 */
public class PayResulActivity extends SimpleActivity {


    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_ico)
    ImageView ivIco;
    @BindView(R.id.tv_result)
    TextView tvResult;
    @BindView(R.id.tv_tip)
    TextView tvTip;
    @BindView(R.id.btn_next)
    Button btnNext;
    @BindView(R.id.btn_pay_next2)
    Button btnPayAgain;

    private boolean isPaySuccess;

    @Override
    protected int getLayout() {
        return R.layout.act_pay_result;
    }

    @Override
    protected void initEventAndData() {
        initTitle();
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            isPaySuccess = extras.getBoolean("isPaySuccess", true);
            if (!isPaySuccess) {
                ivIco.setImageResource(R.mipmap.pay_failure_ico);
                tvResult.setText(R.string.pay_failed);
                tvTip.setText(R.string.pay_failed_tip);
                btnNext.setText(R.string.re_pay);
                btnPayAgain.setText(R.string.back_home);
//                return;
            }
//            ivIco.setImageResource(R.mipmap.pay_successful_ico);
//            tvResult.setText(R.string.pay_successed);
//            tvTip.setText(R.string.pay_success_tip);
//            btnNext.setText(R.string.order_now);
//            btnPayAgain.setText(R.string.pay_again);
        }
    }

    private void initTitle() {
        ImmersionBar.with(this).statusBarColor(R.color.white)
                .statusBarDarkFont(true).navigationBarColor(R.color.white).init();
        tvTitle.setText("充值结果");
    }

    @OnClick({R.id.iv_back, R.id.btn_next, R.id.btn_pay_next2})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                ActivityUtils.finishActivity(this);
                break;
            case R.id.btn_next:
                if(isPaySuccess) {
                    ActivityUtils.startActivity(MainActivity.class);
                    return;
                }
                ActivityUtils.finishActivity(this);
                break;
            case R.id.btn_pay_next2:
                if(isPaySuccess) {
                    ActivityUtils.finishActivity(this);
                    return;
                }
                ActivityUtils.startActivity(MainActivity.class);
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().post(new CommonBean(Constants.CODE_REFRESH));
    }

}
